package com.example.superoa.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.KqRecess;
import com.example.superoa.model.pojos.LeaveType;
import com.example.superoa.model.service.LeaveClassService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class LeaveClassController {
	@Autowired
	private LeaveClassService ser;
	//kq-leave-class 页面table初始化值
	@RequestMapping("leaveclass_selectAll")
	@ResponseBody
	public Map<String,Object> LeaveSelectAll(int page,int rows) {
		Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		JSONArray json = ser.LeaveSelectAll();
		int i=1;
		for (Object object : json) {
			JSONObject obj=(JSONObject) object;
			if(obj.get("LT_QI").equals(1)) {
				obj.put("qi", "已启用");
			}else {
				obj.put("qi", "未启用");
			}
			obj.put("sortable", i);
			i++;
		}
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", json);
		return map;
	}
	//kq-leave-class 修改按钮查询
	@RequestMapping("selectQingId")
	@ResponseBody
	public JSONObject selectid(int id) {
		return ser.selectQingId(id);
	}
	//kq-leave-class 新增修改
	@PostMapping("add_qingjia")
	public String addqin(String LT_ID,String LT_NAME,BigDecimal LT_ZUI,String LT_DAN,Integer LT_QI) {
		LeaveType lt=new LeaveType();
		try {
			lt.setLtId(Integer.parseInt(LT_ID));
		} catch (Exception e) {
				// TODO: handle exception
		}
		lt.setLtName(LT_NAME);
		lt.setLtZui(LT_ZUI);
		lt.setLtDan(LT_DAN);
		lt.setLtQi(LT_QI);
		ser.addQingjia(lt);
		return "redirect:main-administrator:kq-leave-class";
	}
	@RequestMapping("delect_qing")
	public String delectqin(Integer id) {
		ser.delectqing(id);
		return "redirect:main-administrator:kq-leave-class";
	}
}
